package assignment1;
/*
 * @author jc198809
 */
import java.io.*;
import assignment1.Inventory;
public class Main {
    public static void main(String[] args) {
        String userInput = null;
        char convertedUserInput = ' ';
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        //Make Linked List
        Inventory listStart = new Inventory();
        readFile();
        listStart.set_data("Test Name", 4);
        writeFile(listStart);

        do{
            userInput = " ";
            System.out.println("Inventory Menu");
            System.out.println("1: List Products");
            System.out.println("2: List Inventory");
            System.out.println("3: List Inventory with required Parts");
            System.out.println("Q: Quit");
            System.out.print("Selection:");

            try {
                userInput = br.readLine();
            }
            catch (IOException ioe) {
                 System.out.println("IO error reading input");
                 System.exit(1);
            }

            userInput = userInput.toUpperCase();

            System.out.println("");
            convertedUserInput = userInput.charAt(0);

            switch (convertedUserInput){

                case '1':
                    
                    break;
                case '2':
                    printItems();
                    break;
            }

        } while (convertedUserInput != 'Q');

        System.out.println(" ");
    }

    /*static void addItem(Inventory startOfList){
        String userInput = null;
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        Inventory cursor = null;
       
        System.out.println("Add Items to Inventory");
        System.out.print("Name of Item:");
        try {
            userInput = br.readLine();
        }
        catch (IOException ioe) {
            System.out.println("IO error reading input");
            System.exit(1);
        }

        cursor = startOfList;
        Inventory newItem = new Inventory();
        newItem.set_link(cursor);
        


        System.out.print("Quantity");
  
        //startOfList.set_data("test", 4);
        // add to current number of inventory;

    }*/

    static void printItems(){
        // cout current number of inventory;

    }

    static void readFile(){
        try{
            File myFile = new File("MyText.txt");
            FileReader fileReader = new FileReader(myFile);

            BufferedReader reader = new BufferedReader(fileReader);

            String line = null;

            while ((line = reader.readLine())!= null){
                System.out.println(line);
            }
            //increment counter to know how many items
            reader.close();
        } catch(Exception ex){
            ex.printStackTrace();
        }
    }

    static void writeFile(Inventory inventoryList){
        try{
            FileWriter writer = new FileWriter("FooBar.txt");
            //BufferedWriter writer2 = new BufferedWriter(fileWriter);
            writer.write("[Qty],");
            writer.write("[Item Name]");
            writer.write("\r\n"); //New Line
            writer.write("-----------------------------------------");
            writer.write("\r\n"); //New Line


            //loop  # inventory items
            writer.write(inventoryList.getItemQuantity() + ", " +  inventoryList.getItemName() );
            writer.write("\r\n"); //New Line
            writer.write("Foo Bar");
            //end Loop
            writer.close();
        }catch (IOException ex){
            ex.printStackTrace();
        }
    }
}